﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace SynoManager.DownloadStation.Subscriptions
{
    public class LocalSubscriptionStore
    {
        public void Save(Subscription[] subscriptions)
        {
            Debug.WriteLine("Saving subscriptions to local store", "LocalSubscriptionStore");
            Properties.Settings.Default.Subscriptions = subscriptions;
            Properties.Settings.Default.Save();


            // code to test if serialization works (SettingsProvider doesn't throw exceptions :( )

            //XmlSerializer ser = new XmlSerializer(typeof(Subscription[]));
            //Stream stream = new FileStream(@"C:/test.xml", FileMode.CreateNew, FileAccess.Write);
            //ser.Serialize(stream, subscriptions);
            //stream.Close();
        }

        public Subscription[] Load()
        {
            Debug.WriteLine("Loading subscriptions from local store", "LocalSubscriptionStore");
            return Properties.Settings.Default.Subscriptions ?? new Subscription[0];
        }
    }
}
